package fr.mbds.first.wallet.entity;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import fr.mbds.first.wallet.R;

public class OperationAdapter extends ArrayAdapter {
	private final Context context;
	private final List<Operation> values;

	public OperationAdapter(Context context, List<Operation> v) {
		super(context, R.layout.layout_adapter_operation, v);
		this.context = context;
		this.values = v;
	}


	@Override
	public int getCount() {
		return values.size();
	}

	@Override
	public Object getItem(int arg0) {
		return values.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View adapterView = inflater.inflate(R.layout.layout_adapter_operation, parent, false);
		
		TextView textViewDetails = (TextView) adapterView.findViewById(R.id.TextView_OperationAdapter_Details);
		String operationDetails = values.get(position).getDetails();
		textViewDetails.setText(operationDetails);
		
		TextView textViewDate = (TextView) adapterView.findViewById(R.id.TextView_OperationAdapter_Date);
		String operationDate = values.get(position).getDate().toString();
		textViewDate.setText(operationDate);
		
		TextView textViewValue = (TextView) adapterView.findViewById(R.id.TextView_OperationAdapter_Value);
		String operationValue = values.get(position).getValue()+"";
		textViewValue.setText(operationValue);

		return adapterView;
	}
} 
